<template>
    <el-dialog v-model="open" title="插入订单" width="510px">
        <el-form ref="formRef" :model="formData" :rules="formRules" label-width="100px">
            <el-form-item label="数量" prop="showAmount">
                <el-input v-model="formData.showAmount" placeholder="请输入数量" />
            </el-form-item>
            <el-form-item label="收益率1" prop="showRate1">
                <el-input v-model="formData.showRate1" placeholder="请输入收益率1" />
            </el-form-item>
            <el-form-item label="收益率2" prop="showRate2">
                <el-input v-model="formData.showRate2" placeholder="请输入收益率2" />
            </el-form-item>
            <el-form-item label="收益率3" prop="showRate3">
                <el-input v-model="formData.showRate3" placeholder="请输入收益率3" />
            </el-form-item>
            <el-form-item label="实际数量" prop="realAmount">
                <el-input v-model="formData.realAmount" placeholder="请输入实际数量" />
            </el-form-item>
            <el-form-item label="详情1" prop="details1">
                <el-input v-model="formData.details1" placeholder="请输入详情1" />
            </el-form-item>
            <el-form-item label="详情2" prop="details2">
                <el-input v-model="formData.details2" placeholder="请输入详情2" />
            </el-form-item>
            <el-form-item label="详情3" prop="details3">
                <el-input v-model="formData.details3" placeholder="请输入详情3" />
            </el-form-item>

        </el-form>
        <template #footer>
            <span class="dialog-footer">
                <el-button type="primary" :loading="loading" @click="onSubmit('formData')">确定</el-button>
            </span>
        </template>
    </el-dialog>
</template>
<script setup>
import { reactive, ref, defineExpose, defineEmits } from 'vue'
import { insertOrder } from "@/api";
import { ElMessageBox, ElMessage } from "element-plus";
const emit = defineEmits(['loadData'])
const formRef = ref()
const open = ref(false)
const formData = reactive({
    showAmount: "",
    showRate1: "",
    showRate2: "",
    showRate3: "",
    realAmount: "",
    details1: "",
    details2: "",
    details3: "",
})
const formRules = {
    showAmount: [
        { required: true, message: '请输入数量', trigger: 'change' },
    ], showRate1: [
        { required: true, message: '请输入收益率1', trigger: 'change' },
    ], showRate2: [
        { required: true, message: '请输入收益率2', trigger: 'change' },
    ], showRate3: [
        { required: true, message: '请输入收益率3', trigger: 'change' },
    ], realAmount: [
        { required: true, message: '请输入实际数量', trigger: 'change' },
    ], details1: [
        { required: true, message: '请输入详情1', trigger: 'change' },
    ], details2: [
        { required: true, message: '请输入详情2', trigger: 'change' },
    ], details3: [
        { required: true, message: '请输入详情3', trigger: 'change' },
    ],
}
const loading = ref(false)
const onSubmit = async () => {
    try {
        const a = await formRef.value.validate().catch(() => null)
        if (!a) return
        open.value = false;
        const res = await insertOrder(formData);
        if (res.data.code == 20) {
            ElMessage({
                message: "成功",
                type: "success",
            });
        }
        emit("loadData")
    } catch (error) {

    }
}
const show = (row) => {
    open.value = true;
}
defineExpose({
    show,
})
</script>
<style lang="scss" scoped>
.right {
    overflow: auto;
}

.el-pagination {
    padding: 15px;
    float: right;
}
</style>